// pages/home/home.js
const app = getApp();
var { _get_activities } = require('../../utils/xiaohuangyu')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activities: [],
    totalResult: 0,
    params: {
      currentPage: 1
    },
    activity_type: {
      1: {
        name: '投票',
        color: 'blue'
      },
      2: {
        name: '砍价',
        color: 'red'
      }
    },
    gridCol: 3,
    iconList: [
      {
        icon: 'group_fill',
        color: 'yellow',
        badge: 0,
        name: '我的活动'
      }, {
        icon: 'timefill',
        color: 'red',
        badge: 120,
        name: '预热活动'
      }, {
        icon: 'questionfill',
        color: 'orange',
        badge: 1,
        name: '新人攻略'
      }],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },
  activeDetailTap(res) {
    const activity_type = res.currentTarget.dataset.activity_type
    const id = res.currentTarget.dataset.id
    switch (activity_type) {
      case 1:
        wx.navigateTo({
          url: './vote/vote?id=' + id,
        })
        break;
      case 2:
        wx.navigateTo({
          url: './bargain/bargain?id=' + id,
        })
        break;
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    _get_activities(this.data.params, res => {
      console.log('_get_activities', res)
      if (res.status) {
        this.setData({
          activities: res.data.dataList,
          totalResult: res.data.totalResult,
          ['params.currentPage']: res.data.currentPage
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})